<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>OpenCV图像读取与显示 | 洛沐の人间客栈</title><meta name="keywords" content="Python数字图像处理"><meta name="author" content="洛沐,guojiaxiang0820@gmail.com"><meta name="copyright" content="洛沐"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="OpenCV是一个强大的图像处理的函数库，里面包含了数种经典函数，用于数字图像处理程序的调用。">
<meta property="og:type" content="article">
<meta property="og:title" content="OpenCV图像读取与显示">
<meta property="og:url" content="https://www.guojxblog.cn/archives/8063fed6.html">
<meta property="og:site_name" content="洛沐の人间客栈">
<meta property="og:description" content="OpenCV是一个强大的图像处理的函数库，里面包含了数种经典函数，用于数字图像处理程序的调用。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/hefu.jpeg">
<meta property="article:published_time" content="2022-05-13T15:25:17.000Z">
<meta property="article:modified_time" content="2023-01-18T13:44:27.630Z">
<meta property="article:author" content="洛沐">
<meta property="article:tag" content="Python数字图像处理">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/hefu.jpeg"><link rel="shortcut icon" href="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/RS_icon.jpg"><link rel="canonical" href="https://www.guojxblog.cn/archives/8063fed6"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="baidu-site-verification" content="code-zGPrfnFp7y"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: {"limitDay":180,"position":"top","messagePrev":"此文中创建于","messageNext":"天之前，请以最新文章为准！"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":500},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: true
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: 洛沐","link":"链接: ","source":"来源: 洛沐の人间客栈","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'OpenCV图像读取与显示',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-01-18 21:44:27'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/style.css"><link rel="stylesheet" href="/css/iconfont.css"><link rel="stylesheet" href="/css/font-awesome.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><script src="/live2d-widget/autoload.js"></script><meta name="generator" content="Hexo 6.1.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/touxiang.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">29</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-graduation-cap"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-heart-pulse"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book-reader"></i><span> 读书</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-keyboard"></i><span> 动态</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言</span></a></li><li><a class="site-page child" href="/notes/"><i class="fa-fw fas fa-feather-alt"></i><span> 随笔</span></a></li><li><a class="site-page child" href="/ideas/"><i class="fa-fw fa-solid fa-lightbulb"></i><span> 妙想</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/hefu.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">洛沐の人间客栈</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-graduation-cap"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-heart-pulse"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book-reader"></i><span> 读书</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-keyboard"></i><span> 动态</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言</span></a></li><li><a class="site-page child" href="/notes/"><i class="fa-fw fas fa-feather-alt"></i><span> 随笔</span></a></li><li><a class="site-page child" href="/ideas/"><i class="fa-fw fa-solid fa-lightbulb"></i><span> 妙想</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">OpenCV图像读取与显示</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-05-13T15:25:17.000Z" title="发表于 2022-05-13 23:25:17">2022-05-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-01-18T13:44:27.630Z" title="更新于 2023-01-18 21:44:27">2023-01-18</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81/">程序代码</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="OpenCV图像读取与显示"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="OpenCV简介"><a href="#OpenCV简介" class="headerlink" title="OpenCV简介"></a>OpenCV简介</h2><p>OpenCV是一个强大的图像处理的函数库，里面包含了数种经典函数，用于数字图像处理程序的调用。</p>
<h2 id="数字图像处理"><a href="#数字图像处理" class="headerlink" title="数字图像处理"></a>数字图像处理</h2><p>将图像数字化称为数字图像，将数字图像进行转化成多维数组，进行数学上的统计与计算，用以提高图像质量以便增加人眼的识别效果的方法成为数字图像处理。其中Python数字图像处理非常流行，如今已经有机器学习，卷积神经网络，深度学习等算法在计算机视觉，遥感与摄影测量等领域应用。</p>
<h2 id="代码详解"><a href="#代码详解" class="headerlink" title="代码详解"></a>代码详解</h2><blockquote>
<p>方法一：</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="comment"># import numpy as np</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">在读取真彩色RGB三波段图像时，需要用到openCV开源库中的函数，较为方便，但也可以自己写函数处理，openCV是专门用于图像处理的开源库，</span></span><br><span class="line"><span class="string">应用较为方便简单所以本程序应用到了其split函数，就是为了分出图像的三个通道。</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="comment"># Step 1：读取图像并显示保存</span></span><br><span class="line"><span class="comment"># 读取图像，应用openCV的imread函数</span></span><br><span class="line">img = cv2.imread(<span class="string">&quot;Typhoon Chanthu image09182021_500m.jpeg&quot;</span>)</span><br><span class="line"><span class="comment"># 显示图像，应用openCV的imshow函数</span></span><br><span class="line">cv2.imshow(<span class="string">&quot;Color&quot;</span>, img)</span><br><span class="line"><span class="comment"># 利用openCV的split函数将彩色图像的R、G、B三个波段的灰度图分开，并将其值赋给b,g,r</span></span><br><span class="line"><span class="comment"># 在此需要注意的是，第n波段是图像的第3维信息，在python中顺序是从0开始的，所以波段对应为0对应b（蓝波段），</span></span><br><span class="line"><span class="comment"># 1对应g（绿波段），2对应r（红波段）</span></span><br><span class="line">b, g, r = cv2.split(img)</span><br><span class="line"><span class="comment"># 分别显示三个波段的图像，显示框标题分别设为：&quot;Blue 1&quot;，&quot;Green 1&quot;，&quot;Red 1&quot;</span></span><br><span class="line">cv2.imshow(<span class="string">&quot;Blue&quot;</span>, b)</span><br><span class="line">cv2.imshow(<span class="string">&quot;Green&quot;</span>, g)</span><br><span class="line">cv2.imshow(<span class="string">&quot;Red&quot;</span>, r)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 分别将图像的三个波段写出</span></span><br><span class="line">cv2.imwrite(<span class="string">&quot;typtoon_r.jpg&quot;</span>, r)</span><br><span class="line">cv2.imwrite(<span class="string">&quot;typtoon_g.jpg&quot;</span>, g)</span><br><span class="line">cv2.imwrite(<span class="string">&quot;typtoon_b.jpg&quot;</span>, b)</span><br><span class="line"><span class="comment"># 这里出现了error，如果需要显示图像窗口时，如imshow图像的时候，需要加上cv2.waitKay()函数，控制着imshow的持续时间</span></span><br><span class="line"><span class="comment"># 其中waitKay()函数中的参数值代表弛豫时间，0和不填代表无限制时间，也就是说，图像显示窗口无限制时间显示。若是其他数字，</span></span><br><span class="line"><span class="comment"># 则是以毫秒为计数单位，写多少就代表图像显示多少毫秒。需要注意的是，窗口显示图像时，按任意键会结束显示。</span></span><br><span class="line">cv2.waitKey(<span class="number">1</span>)</span><br><span class="line"><span class="comment"># cv2.destroyAllWindows() 用来删除窗口的，（）里不指定任何参数，则删除所有窗口，删除特定的窗口，往（）输入特定的窗口值。</span></span><br><span class="line">cv2.destroyAllWindows()</span><br><span class="line"></span><br><span class="line"><span class="comment"># Step 2 读取各个波段的像素值</span></span><br><span class="line"><span class="comment"># 首先打印图像的信息</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;图像形状大小：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.shape)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;图像像素数目：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.size)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;图像数据类型：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.dtype)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点（左上角）(0,0)的各个通道值，在此item()函数则是字典函数，遍历图像找到图像中的像素值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(0,0)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">0</span>, <span class="number">0</span>, <span class="number">2</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(0,0)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(0,0)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(838, 757)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(838,757)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">838</span>, <span class="number">757</span>, <span class="number">2</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(838,757)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">838</span>, <span class="number">757</span>, <span class="number">1</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(838,757)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">838</span>, <span class="number">757</span>, <span class="number">0</span>))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(726, 1287)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(726,1287)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">726</span>, <span class="number">1287</span>, <span class="number">2</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(726,1287)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">726</span>, <span class="number">1287</span>, <span class="number">1</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(726,1287)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">726</span>, <span class="number">1287</span>, <span class="number">0</span>))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(2096, 1870)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2096,1870)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">2096</span>, <span class="number">1870</span>, <span class="number">2</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2096,1870)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">2096</span>, <span class="number">1870</span>, <span class="number">1</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2096,1870)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">2096</span>, <span class="number">1870</span>, <span class="number">0</span>))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(2168, 2014)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2168,2014)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">2168</span>, <span class="number">2014</span>, <span class="number">2</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2168,2014)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">2168</span>, <span class="number">2014</span>, <span class="number">1</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2168,2014)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.item(<span class="number">2168</span>, <span class="number">2014</span>, <span class="number">0</span>))</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>方法二：</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="comment"># from PIL import Image</span></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">在提取图像中的像素值时，首先需要将图像转化为数组，对数组进行提取，因此需要用到numpy库。</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="comment"># Step 1：读取图像，并显示和储存</span></span><br><span class="line">img = cv2.imread(<span class="string">&quot;Typhoon Chanthu image09182021_500m.jpeg&quot;</span>)</span><br><span class="line">cv2.imshow(<span class="string">&quot;Color 2&quot;</span>, img)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># cv2.imshow(&quot;img&quot;,img)</span></span><br><span class="line"><span class="comment"># b, g, r = cv2.split(img)</span></span><br><span class="line"><span class="comment"># cv2.imshow(&quot;Blue 1&quot;, b)</span></span><br><span class="line"><span class="comment"># cv2.imshow(&quot;Green 1&quot;, g)</span></span><br><span class="line"><span class="comment"># cv2.imshow(&quot;Red 1&quot;, r)</span></span><br><span class="line"><span class="comment"># cv2.waitKey()</span></span><br><span class="line"><span class="comment"># cv2.destroyAllWindows()</span></span><br><span class="line"><span class="comment"># 此处没有用openCV中的split函数进行RGB图的拆分，而是定义了三个拆分函数，其效果与split函数一致。</span></span><br><span class="line"><span class="comment"># 第一函数get_red(),输入参数为三波段RGB图像，其中2，1，0分别对应蓝，绿，红三个波段</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">get_red</span>(<span class="params">img</span>):</span><br><span class="line">    redImg = img[:, :, <span class="number">2</span>]</span><br><span class="line">    <span class="keyword">return</span> redImg</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">get_green</span>(<span class="params">img</span>):</span><br><span class="line">    greenImg = img[:, :, <span class="number">1</span>]</span><br><span class="line">    <span class="keyword">return</span> greenImg</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">get_blue</span>(<span class="params">img</span>):</span><br><span class="line">    blueImg = img[:, :, <span class="number">0</span>]</span><br><span class="line">    <span class="keyword">return</span> blueImg</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 应用上述定义函数进行波段赋值</span></span><br><span class="line">b = get_blue(img)</span><br><span class="line">g = get_green(img)</span><br><span class="line">r = get_red(img)</span><br><span class="line"><span class="comment"># 再将三个波段用窗口展示</span></span><br><span class="line">cv2.imshow(<span class="string">&quot;Blue 2&quot;</span>, b)</span><br><span class="line">cv2.imshow(<span class="string">&quot;Green 2&quot;</span>, g)</span><br><span class="line">cv2.imshow(<span class="string">&quot;Red 2&quot;</span>, r)</span><br><span class="line"><span class="comment"># 分别将图像的三个波段写出</span></span><br><span class="line">cv2.imwrite(<span class="string">&quot;typtoon2_r.jpg&quot;</span>, r)</span><br><span class="line">cv2.imwrite(<span class="string">&quot;typtoon2_g.jpg&quot;</span>, g)</span><br><span class="line">cv2.imwrite(<span class="string">&quot;typtoon2_b.jpg&quot;</span>, b)</span><br><span class="line"><span class="comment"># 定义弛豫时间，按任意键结束</span></span><br><span class="line">cv2.waitKey()</span><br><span class="line"><span class="comment"># 关闭窗口</span></span><br><span class="line">cv2.destroyAllWindows()</span><br><span class="line"></span><br><span class="line"><span class="comment"># Step 2：获取图像的像素值</span></span><br><span class="line"><span class="comment"># 首先打印图像的信息</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;图像形状大小：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.shape)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;图像像素数目：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.size)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;图像数据类型：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img.dtype)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 此为第二种获取图像像素值的方法，需要将图像先转化为三维数组np.array(),然后输出数组对应的值来获取图像的像素值</span></span><br><span class="line"><span class="comment"># 将图像转化为数组</span></span><br><span class="line">img_array = np.array(img)</span><br><span class="line"><span class="comment"># 利用数组的位置（三维坐标）来获取所需的像素值</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点（左上角）(0,0)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(0,0)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">0</span>, <span class="number">0</span>, <span class="number">2</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(0,0)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(0,0)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(838, 757)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(838,757)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">838</span>, <span class="number">757</span>, <span class="number">2</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(838,757)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">838</span>, <span class="number">757</span>, <span class="number">1</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(838,757)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">838</span>, <span class="number">757</span>, <span class="number">0</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(726, 1287)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(726,1287)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">726</span>, <span class="number">1287</span>, <span class="number">2</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(726,1287)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">726</span>, <span class="number">1287</span>, <span class="number">1</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(726,1287)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">726</span>, <span class="number">1287</span>, <span class="number">0</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(2096, 1870)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2096,1870)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">2096</span>, <span class="number">1870</span>, <span class="number">2</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2096,1870)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">2096</span>, <span class="number">1870</span>, <span class="number">1</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2096,1870)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">2096</span>, <span class="number">1870</span>, <span class="number">0</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 打印像素点(2168, 2014)的各个通道值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2168,2014)的R通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">2168</span>, <span class="number">2014</span>, <span class="number">2</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2168,2014)的G通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">2168</span>, <span class="number">2014</span>, <span class="number">1</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;像素点(2168,2014)的B通道值为：&quot;</span>)</span><br><span class="line"><span class="built_in">print</span>(img_array[<span class="number">2168</span>, <span class="number">2014</span>, <span class="number">0</span>])</span><br></pre></td></tr></table></figure>



<h2 id="结果展示"><a href="#结果展示" class="headerlink" title="结果展示"></a>结果展示</h2><blockquote>
<p>（1）RGB真彩色影像</p>
</blockquote>
<p><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/TyphoonChanthuimage09182021_500m.jpeg" alt="RGB真彩色影像"></p>
<blockquote>
<p>（2）红色通道R</p>
</blockquote>
<p><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/R.png" alt="红色通道R"></p>
<blockquote>
<p>（3）绿色通道G</p>
</blockquote>
<p><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/G.png" alt="绿色通道G"></p>
<blockquote>
<p>（4）蓝色通道B</p>
</blockquote>
<p><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/B.png" alt="蓝色通道B"></p>
<blockquote>
<p>代码与结果详见：</p>
</blockquote>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/guojx0820/OpenCVImgReadAndShow"><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://github-readme-stats.vercel.app/api/pin/?username=guojx0820&repo=OpenCVImgReadAndShow&theme=radical" alt="OpenCVImgReadAndShow"></a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:guojiaxiang0820@gmail.com" rel="external nofollow noreferrer">洛沐</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.guojxblog.cn/archives/8063fed6.html">https://www.guojxblog.cn/archives/8063fed6.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.guojxblog.cn" target="_blank">洛沐の人间客栈</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86/">Python数字图像处理</a></div><div class="post_share"><div class="social-share" data-image="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Python%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86%E5%9F%BA%E7%A1%80%E4%B9%8BOpenCV%E5%9B%BE%E5%83%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%98%BE%E7%A4%BA/hefu.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/wechat.jpeg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/wechat.jpeg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/alipay.jpeg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/alipay.jpeg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/archives/a8ccf4cb.html"><img class="prev-cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/ComeDate.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">高斯——勒让德求积公式与复化高斯型求积公式(等距节点)误差分析</div></div></a></div><div class="next-post pull-right"><a href="/archives/a1db3116.html"><img class="next-cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/movies.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">肖申克的救赎——经久不衰的经典之作</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81NjIzOS8zMjcwMg=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#OpenCV%E7%AE%80%E4%BB%8B"><span class="toc-number">1.</span> <span class="toc-text">OpenCV简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E5%AD%97%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86"><span class="toc-number">2.</span> <span class="toc-text">数字图像处理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E8%AF%A6%E8%A7%A3"><span class="toc-number">3.</span> <span class="toc-text">代码详解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%93%E6%9E%9C%E5%B1%95%E7%A4%BA"><span class="toc-number">4.</span> <span class="toc-text">结果展示</span></a></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023  <i id="heartbeat" class="fa fas fa-heartbeat"></i> 洛沐</div><div class="footer_custom_text">谢谢你来看<a href="https://www.guojxblog.cn/" style='color:red;Font-size:36'>我</a>，你今天真好看😘</div></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">簡</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">本地搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !true) {
  if (true) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><script src="/js/mobile_side.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><div class="pjax-reload"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1s');
    arr[i].setAttribute('data-wow-delay', '700ms');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
}</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
}</script></div><script defer="defer" src="https://cdn.jsdelivr.net/gh/graingert/wow@1.3.0/dist/wow.min.js"></script><script defer="defer" src="/js/wow_init.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script>
            window.imageLazyLoadSetting = {
                isSPA: true,
                preloadRatio: 3,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(n){n.imageLazyLoadSetting.processImages=o;var e=n.imageLazyLoadSetting.isSPA,i=n.imageLazyLoadSetting.preloadRatio||1,r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]"));function o(){e&&(r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")));for(var t,a=0;a<r.length;a++)0<=(t=(t=r[a]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(n.innerHeight*i||document.documentElement.clientHeight*i)&&function(){var t,e,n,i,o=r[a];t=o,e=function(){r=r.filter(function(t){return o!==t})},n=new Image,i=t.getAttribute("data-original"),n.onload=function(){t.src=i,e&&e()},t.src!==i&&(n.src=i)}()}o(),n.addEventListener("scroll",function(){var t,e;t=o,e=n,clearTimeout(t.tId),t.tId=setTimeout(function(){t.call(e)},500)})}(this);</script><script async>window.onload=function(){var a=document.createElement('script'),b=document.getElementsByTagName('script')[0];a.type='text/javascript',a.async=!0,a.src='/sw-register.js?v='+Date.now(),b.parentNode.insertBefore(a,b)};</script></body></html>